package cn.kinoko.service.cnTeam.impl;

import cn.kinoko.common.aspect.annotation.Cacheable;
import cn.kinoko.common.base.model.BaseServiceImpl;
import cn.kinoko.common.constant.CacheKeyConstant;
import cn.kinoko.mapper.cnTeam.PositionMapper;
import cn.kinoko.model.cnTeam.entity.Position;
import cn.kinoko.service.cnTeam.PositionService;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author kinoko
 */
@Service
public class PositionServiceImpl extends BaseServiceImpl<PositionMapper, Position> implements PositionService {

    /**
     * 查询所有职位
     *
     * @return 职位列表
     */
    @Cacheable(key = CacheKeyConstant.POSITION_KEY, params = "#type")
    @Override
    public Map<Long, String> queryAll(Integer type) {
        return lambdaQuery().list().stream()
                .filter(position -> type == null || position.getType().equals(type))
                .collect(Collectors.toMap(Position::getId, Position::getName));
    }

}